package com.springpad;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.database.NoteAdapter;
import com.model.Note;

import firstdroid.tutorial.gridview.R;


public class AddNote extends Activity {

	AlertDialog.Builder alert;
	NoteAdapter na;
	
	String nid;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.addnote);
		
		na = new NoteAdapter(getApplicationContext());
		nid=getIntent().getExtras().getString("nbid");
		final int notebookid=Integer.parseInt(nid);
		Button b = (Button) findViewById(R.id.button1);
		Button c = (Button) findViewById(R.id.button2);
		final TextView name = (TextView) findViewById(R.id.editText2);
		final TextView content = (TextView) findViewById(R.id.editText1);
		b.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String noteName = name.getText().toString();
				String notecontent = content.getText().toString();
				
				
				createNewNote(noteName, notecontent,notebookid);
				
				Intent i=new Intent(AddNote.this,ViewNote.class);
				i.putExtra("nbid",nid);
				startActivity(i);
				//startActivity(new Intent(AddNote.this,ViewNote.class));
			}
		});
		c.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent i=new Intent(AddNote.this,Menu.class);
				i.putExtra("nbid",nid);
				startActivity(i);
				//startActivity(new Intent(AddNote.this,Menu.class));
			}
		});

	}

	

	private void createNewNote(String noteName, String notecontent,int notebookid) {
		Note n = new Note();
		n.setName(noteName);
		n.setContent(notecontent);
		n.setNotebookid(notebookid);
		Log.d("-----",noteName);
		Log.d("++++",notecontent);
		Log.d("++++",notebookid+"");
		na.open();
		na.createNote(n);
		na.close();

	}
}